<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header">

</head>
<body class="hold-transition skin-blue sidebar-mini">
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
<section class="content-header">
    <h1>
        合同提交
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目编号</label>
                                    <input type="text" name="contName" class="form-control" placeholder="项目编号" >
                                </div>
                                <!--<div class="form-group" style="margin-right: 10px;">-->
                                    <!--<label>买方合同编号</label>-->
                                    <!--<input type="text" name="buyCode" class="form-control" placeholder="买方合同编号">-->
                                <!--</div>-->
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>卖方合同编号</label>
                                    <input type="text" name="sellCode" class="form-control" placeholder="卖方合同编号">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>买方</label>
                                    <input type="text" name="totalMethod" class="form-control" placeholder="买方">
                                </div>

                                <div class="form-group" style="margin-right: 10px;margin-top: 5px;">
                                    <label>类别</label>
                                    <select class="form-control" name="contType" >
                                        <option value="">全部</option>
                                        <option value="对外销售">对外销售</option>
                                        <option value="对内销售">对内销售</option>
                                        <option value="合作制造">合作制造</option>
                                    </select>
                                </div>

                                <div class="form-group" style="margin-right: 10px;margin-top: 5px;">
                                    <label>合同任务状态</label>
                                    <select name="isStatue" class="form-control" style="width:200px;">
                                        <option  value="1" selected="selected">未提交</option>
                                        <option  value="3">待组级审</option>
                                        <option  value="4">待科级审</option>
                                        <option  value="6">待部级审</option>
                                        <option  value="100">已提交</option>
                                    </select>
                                </div>
                                <!--<div class="form-group" style="margin-right: 10px;">-->
                                <!--<label>报价创建人</label>-->
                                <!--<input type="text" name="supplierAttn" class="form-control" placeholder="报价创建人">-->
                                <!--</div>-->
                                <!--<div class="form-group" style="margin-right: 10px;">-->
                                <!--<label>报价时间</label>-->
                                <!--<input type="text" name="quoteGentDate" class="form-control" placeholder="报价创建时间">-->
                                <!--</div>-->

                                <button type="button" class="btn btn-success" id="btn-search" style="margin-top: 5px;">
                                    <!--<i class="fa fa-search"></i>-->
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"  class="table-border" style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
    <!--修改合同登记人-->
    <div class="modal fade" id="modal-UpdUser">
        <div class="modal-dialog" style="width:850px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">修改合同登记人</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group col-md-6 has-feedback" style=" margin-top: 10px;">
                        <intput id="conid" class="hidden"></intput>
                        <label class="col-md-6 control-label">新的合同登记人</label>
                        <div class="col-md-6">
                            <select class="form-control" id="contWay" name="contWay" data-bv-field="contWay">
                                <option value="">张三</option>
                                <option value="">李四</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer"  style="border: none;">
                    <button type="button" class="btn btn-info" data-dismiss="modal" onclick="saveNewUser()">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer">
</div>
<script th:inline="javascript">
    /** 加载用户表格 */
    table = js.table.init({
        url: ctx + "contractManage/selContractSubmitList",
        showColumns: true,
        showExport: true,
        pageSize:5,
        columns: [
            {
                title: '序号', field: 'id', width: '50',
                formatter: function (value, row, index, field) {
                    var pageSize = table.bootstrapTable('getOptions').pageSize;
                    var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },
            { width:100,title: "项目编号", field: 'contName'},
            { width:120,title: "包含项目", field: 'name'},
            { width:160,title: "卖方合同编号", field: 'sellCode'},
            // { width:160,title: "买方合同编号", field: 'buyCode'},
            { width:160,title: "买方", field: 'totalMethod'},
            { width:80,title: "类别", field: 'contType'},
            { width:80,title: "合同登记人", field: 'createUser'},
            { width:80,title: "创建时间", field: 'contYear'},
            { width:80,title: "合同状态", field: 'contWay'},
            { width:80,title: "登记类型", field: 'parentId',
                 formatter: function (value, row, index) {
                     if(value==0){
                         return "";
                     }else{
                         return "<span class=\"label  badge  label-maroon bg-maroon\">增补合同</span>";
                     }
                }
            },
            { width:100,title: "合同任务状态", field: 'isStatue',
                formatter: function (value, row, index) {
                    if(value==3){
                        return '<span class="label  badge  label-success">已完成</span>';
                    }else if(value==2){
                        return '<span class="label  badge  label-warning">执行中</span>';
                    }else if (value==4) {
                        return '<span class="label  badge  label-danger">被驳回</span>';
                    }else if (value==1) {
                        return '<span class="label  badge  label-warning">保存未提交</span>';
                    }
                }
            },
            {
                title: "操作",
                width: '100',
                formatter: function (value, row, index) {
                    var actions = [];
                    // if(row.isStatue == null || row.isStatue ==''){
                    //     actions.push('<a shiro:hasPermission="con:register:register" class="btn btn-success btn-xs" href="'+ ctx + 'contractManage/contractInfo?quoteId=' + row.fkId + '&conId=0"> 合同登记</a> ');
                    //
                    //     actions.push('<a shiro:hasPermission="con:await:view" class="btn btn-bitbucket btn-xs" href="'+ ctx + 'quoteManage/viewQuotation/quoteId/'+ row.fkId+'"> 查看报价</a> ');
                    // }else
                    if(row.isStatue==1 || row.isStatue==4) {
                        if(row.parentId==0){
                            if(hasP('con:com:edit')){
                                actions.push('<a shiro:hasPermission="con:register:edit" class="btn btn-warning btn-xs" href="'+ ctx + 'contractManage/contractInfo?quoteId=' + row.fkId + '&conId=' + row.id + '" > 编辑</a> ');
                             }
                        }else{
                            if(hasP('con:agr:edit')) {
                               actions.push('<a shiro:hasPermission="con:agr:edit" class="btn btn-warning btn-xs " href="' + ctx + 'contractManage/contractInfoAppend?quoteId=' + row.fkId + '&conId=' + row.id + '&parentId=' + row.parentId + '" > 编辑</a> ');

                            }
                        }
                        // if(hasP('con:await:view')) {
                        //     actions.push('<a shiro:hasPermission="con:await:view" class="btn btn-bitbucket btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.fkId + '"> 查看报价</a> ');
                        // }
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteApp(' + row.id + ')"> 删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApp(' + row.id + ')"> 提交</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="UpdUser(' + row.id + ')"> 修改登记人</a> ');

                    }else{
                        if(hasP('con:regList:view')) {
                                // actions.push('<a shiro:hasPermission="con:regList:view" class="btn btn-info btn-xs" href="' + ctx + 'contractManage/showDetail?quoteId=' + row.fkId + '&conId=' + row.id + '"> 查看</a> ');
                            actions.push('<a target="_blank" class="btn btn-info btn-xs" href="'+ ctx + 'contractManage/contractApproveDetail?quoteId=' + row.fkId + '&conId=' + row.id + '&processId=0&parentId='+row.parentId+'" > 查看</a> ');
                            }
                    }
                    // else if(row.isStatue==2){
                    //     actions.push('<a shiro:hasPermission="con:await:view" class="btn btn-bitbucket btn-xs" href="'+ ctx + 'quoteManage/viewQuotation/quoteId/'+ row.fkId+'"> 查看报价</a> ');
                    //     actions.push('<a shiro:hasPermission="con:regList:view" class="btn btn-info btn-xs" href="'+ ctx + 'contractManage/showDetail?quoteId=' + row.fkId + '&conId=' + row.id + '"> 查看合同</a> ');
                    // }
                    // else if(row.isStatue==3){
                    //     // if(hasP('con:await:view')) {
                    //     //     actions.push('<a shiro:hasPermission="con:await:view" class="btn btn-bitbucket btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.fkId + '"> 查看报价</a> ');
                    //     // }
                    //     if(hasP('con:regList:view')) {
                    //         actions.push('<a shiro:hasPermission="con:regList:view" class="btn btn-info btn-xs" href="' + ctx + 'contractManage/showDetail?quoteId=' + row.fkId + '&conId=' + row.id + '"> 查看</a> ');
                    //     }
                    //     if(hasP('con:agr:view')) {
                    //         actions.push('<a shiro:hasPermission="con:agr:edit" class="btn btn-success btn-xs" href="javascript:void(0)" onclick="delGroup(' + row.id + ')"> 增补协议</a> ');
                    //     }
                    // }
                    // else if(row.isStatue==4){
                    //     if(row.parentId==0){
                    //         if(hasP('con:com:edit')) {
                    //             actions.push('<a shiro:hasPermission="con:register:edit" class="btn btn-warning btn-xs" href="' + ctx + 'contractManage/contractInfo?quoteId=' + row.fkId + '&conId=' + row.id + '" > 编辑</a> ');
                    //         }
                    //     }else{
                    //         if(hasP('con:agr:edit')) {
                    //             actions.push('<a shiro:hasPermission="con:agr:edit" class="btn btn-warning btn-xs" href="' + ctx + 'contractManage/contractInfoAppend?quoteId=' + row.fkId + '&conId=' + row.id + '&parentId=' + row.parentId + '" > 编辑</a> ');
                    //         }
                    //     }
                    //     // if(hasP('con:await:view')) {
                    //     //     actions.push('<a shiro:hasPermission="con:await:view" class="btn btn-bitbucket btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.fkId + '"> 查看报价</a> ');
                    //     // }
                    //     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApp(' + row.id + ')"> 提交</a> ');
                    // }
                    return actions.join('');
                }
            }
        ]
    });
    /**
     * 表格搜索
     */
    $("#btn-search").click(function () {
        js.table.search(table);
    });

    /**
     * 合同id
     * @param contid
     */
    function submitApp(contid){
        js.post({
            url: ctx + "contractManage/contractAppInfo",
            data:{"conId":contid},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {

                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
                js.modal.closeLoading();
            }
        });
    }

    /**
     * 合同id
     * @param contid
     */
    function deleteApp(contid){
        js.post({
            url: ctx + "contractManage/deleteApp",
            data:{"conId":contid},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {

                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
                js.modal.closeLoading();
            }
        });
    }

    /**
     * 修改创建人
     * @param id
     * @constructor
     */
    function UpdUser(id){
        $("#conid").val(id);
        js.post({
            url: ctx + "contractManage/userList",
            data:null,
            success: function (result) {
                debugger;
                if (result.type === web_status.SUCCESS) {
                    if(result.data!=null){
                        var optionHtml="";
                        for(var i=0;i<result.data.rows.length;i++){
                            optionHtml+="<option value=\""+result.data.rows[i].name+"\">"+result.data.rows[i].name+"</option>";
                        }
                    }
                    $("#contWay").html(optionHtml);
                    //js.modal.success(result.msg);
                    js.modal.open("modal-UpdUser");
                } else {
                    js.modal.warning(result.msg);
                }
                js.modal.closeLoading();
            }
        });

    }

    /**
     * 保存新的创建人
     */
    function saveNewUser(){
        js.post({
            url: ctx + "contractManage/updateName",
            data:{"conid":$("#conid").val(),"name":$("#contWay").val()},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success("执行成功");
                    js.table.refresh(table);
                } else {
                    js.modal.warning("执行失败");
                }
            }
        });
    }
</script>